{include file="public/header" /}</head>
<body>
<div class="x-body layui-anim">
    <form class="layui-form" id="form">
        <input type="hidden" name="id" value="{$Request.param.id}">
        <div class="layui-form-item">
            <label class="layui-form-label">地区码</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" value="{$info?$info.code:''}" disabled="disabled"/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">全称</label>
            <div class="layui-input-inline">
                <input type="text" name="full_name" class="layui-input" value="{$info?$info.province.$info.city.$info.district:''}" disabled="disabled"/>
            </div>
        </div>

        {if $info && $info.level>1}
        <div class="layui-form-item">
            <label class="layui-form-label">商城代理编号</label>
            <div class="layui-input-inline">
                <input type="text" name="user_code" class="layui-input" value="{$user_code?$user_code:''}"/>
            </div>
        </div>
        <!--<div class="layui-form-item">
            <label class="layui-form-label">云牧场代理编号</label>
            <div class="layui-input-inline">
                <input type="text" name="pasture_code" class="layui-input" value="{$pasture_code?$pasture_code:''}"/>
            </div>
        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">合约专区代理编号</label>
            <div class="layui-input-inline">
                <input type="text" name="contract_code" class="layui-input" value="{$contract_code?$contract_code:''}"/>
            </div>
        </div>
        {/if}

        <div class="layui-form-item">
            <label class="layui-form-label"></label>
            <button class="layui-btn" lay-filter="add" lay-submit="">
                确认修改
            </button>
        </div>
    </form>
</div>
{include file="public/footer" /}
<script>
    layui.use(['form', 'layer'], function () {
        $ = layui.jquery;
        var form = layui.form
            , layer = layui.layer;

        //监听提交
        form.on('submit(add)', function (data) {
            console.log(data);
            $.ajax({
                type: 'POST',
                url: '{:url("area/save1")}',
                data: $("#form").serialize(),
                dataType: "json",
                success: function (data) {
                    if (data.code == 1) {
                        notify.success(data.msg, 1500, function () {
                            if (window.name != '') {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                parent.window.location.reload();
                            } else {
                                window.location.reload();
                            }
                        });

                    } else {
                        notify.error(data.msg);
                        btn.removeAttr('disabled');
                    }
                }
            });
            return false;
        });

        $("#name").blur(function () {
            var value = $(this).val();
            var split = value.split('/');
            if(split[0]){
                $(".auto_name").val(cap(split[0]));
                $(".db_name").val(split[0]);
            }else{
                $(".auto_name").val('');
                $(".db_name").val('');
            }
        });

        function cap(str) {
            return str.replace(/([a-z])/, function (match, value) {
                return value.toUpperCase();
            })
        }

        form.on('switch(controller)', function(data){
            if(data.elem.checked){
                $(".controller").show();
            }else{
                $(".controller").hide();
            }
        });

        form.on('switch(model)', function(data){
            if(data.elem.checked){
                $(".model").show();
            }else{
                $(".model").hide();
            }
        });


    });
</script>
</body>
</html>